package com.snda.lib.ui;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.Toast;

public class MessageBox {

	protected Context mContext;
	protected String mstrTitle;
	protected String mstrInfo;

	protected DialogInterface.OnClickListener mConfirmListener;
	protected DialogInterface.OnClickListener mCancleListener;
	protected DialogInterface.OnClickListener mNeutralListener;

	protected String mStringOk = "确定";
	protected String mStringCancel = "取消";
	protected String mStringNeutral = "其余";

	public MessageBox(Context context) {
		mContext = context;
	}

	public void setTitle(String strTitle) {
		mstrTitle = strTitle;
	}

	public void setInfo(String strInfo) {
		mstrInfo = strInfo;
	}

	public void setOkText(String strOK) {
		mStringOk = strOK;
	}

	public void setCancelText(String strCancel) {
		mStringCancel = strCancel;
	}

	public void setNeutralText(String strNeutral) {
		mStringNeutral = strNeutral;
	}

	public void setConfirmListener(
			DialogInterface.OnClickListener confirmListener) {
		mConfirmListener = confirmListener;
	}

	public void setCancelListener(DialogInterface.OnClickListener cancelListener) {
		mCancleListener = cancelListener;
	}

	public void setNeutralListener(
			DialogInterface.OnClickListener neutralListener) {
		mNeutralListener = neutralListener;
	}

	protected Dialog buildTipDialog() {
		Builder b1 = new AlertDialog.Builder(mContext);
		b1.setTitle(mstrTitle);
		b1.setMessage(mstrInfo);

		if (mCancleListener != null) {
			b1.setPositiveButton(mStringOk, mConfirmListener);
		}

		if (mConfirmListener != null) {
			b1.setNegativeButton(mStringCancel, mCancleListener);
		}

		if (mNeutralListener != null) {
			b1.setNeutralButton(mStringNeutral, mNeutralListener);
		}

		return b1.create();
	}

	private DialogInterface.OnClickListener confirmListener = new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {

		}
	};

	private DialogInterface.OnClickListener cancelListener = new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {

		}
	};

	public void showDialog(String strTitle, String strInfo,
			DialogInterface.OnClickListener dialogConfirmListener,
			DialogInterface.OnClickListener dialogCancelListener,
			DialogInterface.OnClickListener dialogNeutralListener) {

		mstrTitle = strTitle;
		mstrInfo = strInfo;

		mConfirmListener = dialogConfirmListener;
		mCancleListener = dialogCancelListener;
		mNeutralListener = dialogNeutralListener;

		if (mConfirmListener == null) {
			mConfirmListener = confirmListener;
		}

		if (mCancleListener == null) {
			mCancleListener = cancelListener;
		}

		buildTipDialog().show();
	}

	public void showDialog(String strTitle, String strInfo,
			DialogInterface.OnClickListener dialogConfirmListener,
			DialogInterface.OnClickListener dialogCancleListener) {

		showDialog(strTitle, strInfo, dialogConfirmListener,
				dialogCancleListener, null);
	}

	public void showDialog(String strTitle, String strInfo,
			DialogInterface.OnClickListener dialogConfirmListener) {
		showDialog(strTitle, strInfo, dialogConfirmListener, null, null);
	}

	public void showDialog(String strTitle, String strInfo) {
		showDialog(strTitle, strInfo, null, null, null);
	}

	public void showToast(String strMsg) {
		Toast.makeText(mContext, strMsg, Toast.LENGTH_SHORT).show();
	}

	public static void showToast(Context context, String strMsg) {
		Toast.makeText(context, strMsg, Toast.LENGTH_SHORT).show();
	}

	public static ProgressDialog showProcessDlg(Context context, String strMsg) {
		ProgressDialog dialog = new ProgressDialog(context);
		dialog.setMessage(strMsg);
		return dialog;
	}

}